/* eslint-disable prettier/prettier */
import { Controller, Get, HttpStatus, Param } from '@nestjs/common';
import { AudioService } from './audio.service';
import { RrzArticles } from '../entity/rrz_articles.entity';
import { ApiResponse } from 'src/apiResponse ';

// 控制器负责处理传入请求并向客户端返回响应。
@Controller('audio')
export class AudioController {
  constructor(private readonly audioService: AudioService) {}

  // 获取所有音频
  @Get()
  async findAll(): Promise<RrzArticles[]> {
    return await this.audioService.findAll();
  }

  //获取某个专辑下面的全部音频
  @Get('audiosByCateId/:id')
  async findAudiosByCateId(
    @Param('id') id: string) {
    try {
      const audios = await this.audioService.findAudiosByCateId(id);
      // res.status(200).json(audios);
      return ApiResponse.success(audios);
    } catch (error) {
      console.error(error);  
      return ApiResponse.error(HttpStatus.INTERNAL_SERVER_ERROR, 'Error retrieving items', error.message || 'Internal server error');  
    }
  }

  //获取某个专辑下面的全部音频
  @Get('audiosByCateIdWith/:id')
  async findAudiosByCateIdWith(
    @Param('id') id: string) {
    try {
      const audios = await this.audioService.findAudiosByCateIdWith(id);
      // res.status(200).json(audios);
      return ApiResponse.success(audios);
    } catch (error) {
      console.error(error);  
      return ApiResponse.error(HttpStatus.INTERNAL_SERVER_ERROR, 'Error retrieving items', error.message || 'Internal server error');  
    }
  }
}
